package com.youkeda.bmatch;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author zhoufan
 * @date 2019/1/21
 */
public class FileApplication {

  public static void main(String[] args) {
//    read();
    write();
  }

  public static void write(){
    File file = new File("hello.txt");
    BufferedWriter bw = null;
    try {
      bw = new BufferedWriter(new FileWriter(file));
      bw.write("hello bmatch");
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if(bw != null){
        try {
          bw.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }

  public static void read(){
    File file = new File("bmatch.txt");

    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(file));
      String line;
      while((line = br.readLine()) != null){
        System.out.println(line);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if(br != null){
        try {
          br.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }

}
